package winOrDie.graphics.maps;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * This public class defines the WinOrDie map board structure
 */
public class Map_Board 
{
	private int columns = 0;
	private int rows = 0;
	
	
	private Map_Cell mapCell_Matrix[][] = null;

	/**
	 * This public method returns the number of columns
	 * @return
	 */
	public int getColumns() {
		return columns;
	}

	/**
	 * This public method returns the number of rows
	 * @return
	 */
	public int getRows() {
		return rows;
	}

	/**
	 * This public method returns the {@link Map_Cell} matrix
	 * @return
	 */
	public Map_Cell[][] getMapCell_Matrix() {
		return mapCell_Matrix;
	}

	/**
	 * This constructor initializes the {@link Map_Cell} matrix with the default columns and rows
	 * @throws Exception
	 */
	public Map_Board() throws Exception
	{
		mapCell_Matrix = Map_Board_Factory.get_MapCells(Map_Board_Factory.Default_Columns, Map_Board_Factory.Default_Rows);
		this.columns = Map_Board_Factory.Default_Columns;
		this.rows = Map_Board_Factory.Default_Rows;
	}
	
	/**
	 * This constructor initializes the {@link Map_Cell} matrix with the columns and rows passed as parameter
	 * @param columns
	 * @param rows
	 * @throws Exception
	 */
	public Map_Board(int columns, int rows) throws Exception
	{
		mapCell_Matrix = Map_Board_Factory.get_MapCells(columns, rows);
		this.columns = columns;
		this.rows = rows;
	}
	
	/**
	 * This constructor initializes the {@link Map_Cell} matrix with the {@link Map_Cell} matrix passed as parameter
	 * @param mapCell  
	 * @throws Exception
	 */
	public Map_Board(Map_Cell mapCell[][]) throws Exception
	{
		Map_Board_Factory.check_Map_Cell_Matrix(mapCell);
		columns = mapCell.length;
		rows = mapCell[0].length;
		this.mapCell_Matrix = mapCell;
	}
	
	/**
	 * This public method returns {@link Map_Cell} at position given by parameters
	 * @param column
	 * @param row
	 * @return {@link Map_Cell}
	 * @throws Exception
	 */
	public Map_Cell get_Map_Cell(int column, int row) throws Exception
	{
		Map_Board_Editor.check_Column_And_Row(column, row, this);
		return mapCell_Matrix[column][row];
	}
	
	/**
	 * This public method allows to set a {@link Map_Cell} into {@link Map_Board} 
	 * @param column
	 * @param row
	 * @param mapCell
	 * @throws Exception
	 */
	public void set_Map_Cell(int column, int row, Map_Cell mapCell) throws Exception
	{
		Map_Board_Editor.check_Column_And_Row(column, row, this);
		mapCell_Matrix[column][row] = mapCell;
	}
	
	/**
	 * This public method returns {@link Element} object that contains {@link Map_Board} data
	 * @param document
	 * @return {@link Element}
	 * @throws Exception
	 */
	public Element get_XML_Element(Document document) throws Exception
	{
		return Map_Board_Editor.get_Element_From_Map_Board(this, document);
	}
	
}
